from base.api import BaseApi
from account.controllers import user as user_ctl


class UserApi(BaseApi):

    need_params = {
        'obj_id': ('用户ID', 'required int'),
    }

    def get(self, request, params):
        data = user_ctl.get_user(**params)
        return data


class NextUserApi(BaseApi):

    need_params = {
        'name': ('用户名', 'required str'),
        'account_type': ('证类型', 'required str'),
        'action': ('行为', 'required str'),
    }

    def post(self, request, params):
        data = user_ctl.get_next_user(**params)
        return data


class ExistsUserApi(BaseApi):

    need_params = {
        'name': ('用户名', 'required str'),
    }

    def post(self, request, params):
        data = user_ctl.is_exists_user(**params)
        return data


class UserAccountTypeApi(BaseApi):

    need_params = {
        'name': ('用户名', 'required str'),
    }

    def post(self, request, params):
        data = user_ctl.get_user_account_type(**params)
        return data


class UserTaskApi(BaseApi):

    need_params = {
        'name': ('用户名', 'required str'),
    }

    def post(self, request, params):
        data = user_ctl.get_user_task(**params)
        return data


class UserBaseInfoApi(BaseApi):

    need_params = {
        'obj_id': ('用户ID', 'required int'),
    }

    def get(self, request, params):
        data = user_ctl.get_user_base_info(**params)
        return data


class CreateUserApi(BaseApi):

    need_params = {
        'master_id': ('主账号', 'required str'),
        'slave_id': ('子账号', 'required str'),
        'zone': ('分区', 'required int'),
        'site': ('位置', 'required int'),
        'password': ('密码', 'required str'),
        'name': ('角色名', 'required str'),
    }
    def post(self, request, params):
        user_ctl.create_user(**params)


class BatchCreateUserApi(BaseApi):

    need_params = {
        'master_id': ('主账号', 'required str'),
        'slaves': ('子账号列表', 'required str'),
        'zone': ('分区', 'required int'),
    }
    def post(self, request, params):
        user_ctl.batch_create_users(**params)


class UpdateUserApi(BaseApi):

    need_params = {
        'obj_id': ('用户ID', 'required int'),
        'master_id': ('主账号', 'required str'),
        'slave_id': ('子账号', 'required str'),
        'zone': ('分区', 'required int'),
        'site': ('位置', 'required int'),
        'password': ('密码', 'required str'),
        'name': ('角色名', 'optional str'),
        'task': ('任务', 'optional str'),
    }
    def post(self, request, params):
        user_ctl.update_user(**params)


class DeleteUserApi(BaseApi):

    need_params = {
        'obj_id': ('用户ID', 'required int'),
    }
    def post(self, request, params):
        user_ctl.delete_user(**params)


class ListUserApi(BaseApi):

    need_params = {
        'master_id': ('主账号', 'optional str'),
        'slave_id': ('子账号', 'optional str'),
        'zone': ('分区', 'optional int'),
        'site': ('位置', 'optional int'),
        'job': ('职业', 'optional str'),
        'min_level': ('角色最低等级', 'optional str'),
        'max_level': ('角色最高等级', 'optional str'),
        'min_money': ('最低金币额', 'optional int'),
        'max_money': ('最高金币额', 'optional int'),
        'keyword': ('关键词', 'optional str'),
        'is_online': ('是否在线', 'optional int'),
        'goods_keyword': ('物品关键词', 'optional str'),
        'pet_keyword': ('宠物关键词', 'optional str'),
        'pet_min_level': ('宠物最低等级', 'optional str'),
        'pet_max_level': ('宠物最高等级', 'optional str'),
        'skill_keyword': ('技能关键词', 'optional str'),
        'skill_min_level': ('技能最低等级', 'optional str'),
        'skill_max_level': ('技能最高等级', 'optional str'),
        'has_work': ('是否有工作', 'optional bool'),
        'page_num': ('页码', 'optional int'),
        'page_size': ('页容量', 'optional int'),
    }
    def get(self, request, params):
        data = user_ctl.get_users(**params)
        return data


class SyncUserStatusApi(BaseApi):

    need_params = {
        'name': ('名称', 'required str'),
        'cga_pid': ('CGA PID', 'required int'),
        'cg_pid': ('CG PID', 'required int'),
        'line': ('线路', 'required int'),
    }

    def post(self, request, params):
        user_ctl.sync_user_status(**params)


class SyncUserApi(BaseApi):

    need_params = {
        'name': ('名称', 'required str'),
        'job': ('职业', 'required str'),
        'step': ('阶级', 'required int'),
        'level': ('等级', 'required int'),
        'exp': ('当前经验', 'required int'),
        'gap': ('剩余经验', 'required int'),
        'money': ('背包金额', 'required int'),
        'body': ('身上信息', 'optional'),
        'skill': ('技能信息', 'optional'),
        'bag': ('背包信息', 'optional'),
        'bank': ('银行信息', 'optional'),
    }

    def post(self, request, params):
        user_ctl.sync_user(**params)


class ExportUserApi(BaseApi):

    need_params = {
    }
    def post(self, request, params):
        data = user_ctl.export_users(**params)
        return data


class ImportUserApi(BaseApi):

    need_params = {
        'user_list': ('角色列表', 'required str'),
    }
    def post(self, request, params):
        data = user_ctl.import_users(**params)
        return data


class StatisticsApi(BaseApi):

    need_params = {
    }
    def get(self, request, params):
        data = user_ctl.statistics(**params)
        return data


class RunUsersApi(BaseApi):

    need_params = {
        'users': ('角色列表', 'required list'),
        'line': ('线路', 'required int'),
        'script_id': ('脚本ID', 'optional int'),
        'script_path': ('脚本路径', 'optional str'),
        'json_id': ('配置ID', 'optional int'),
        'json_path': ('配置路径', 'optional str'),
        'injure_stop': ('受伤停止', 'required bool'),
        'soul_stop': ('丢魂停止', 'required bool'),
        'auto_restart': ('自动重启', 'required bool'),
        'auto_login': ('自动登录', 'required bool'),
        'skip_update': ('禁用更新', 'required bool'),
        'auto_change_line': ('自动换线', 'required bool'),
        'auto_create': ('自动创建', 'optional bool'),
        'create_name': ('创建名称', 'optional str'),
        'create_role': ('创建名称', 'optional str'),
        'create_color': ('创建颜色', 'optional str'),
        'create_points': ('创建点数', 'optional str'),
        'create_element': ('创建元素', 'optional str'),
    }

    def post(self, request, params):
        user_ctl.run_users(**params)


class StopUsersApi(BaseApi):

    need_params = {
        'users': ('角色列表', 'required list'),
    }

    def post(self, request, params):
        user_ctl.stop_users(**params)


class CreateScriptApi(BaseApi):

    need_params = {
        'name': ('名称', 'required str'),
        'path': ('路径', 'required str'),
    }
    def post(self, request, params):
        user_ctl.create_script(**params)


class UpdateScriptApi(BaseApi):

    need_params = {
        'obj_id': ('脚本ID', 'required int'),
        'name': ('名称', 'required str'),
        'path': ('路径', 'required str'),
    }
    def post(self, request, params):
        user_ctl.update_script(**params)


class DeleteScriptApi(BaseApi):

    need_params = {
        'obj_id': ('脚本ID', 'required int'),
    }
    def post(self, request, params):
        user_ctl.delete_script(**params)


class ListScriptApi(BaseApi):

    need_params = {
        'page_num': ('页码', 'optional int'),
        'page_size': ('页容量', 'optional int'),
    }
    def get(self, request, params):
        data = user_ctl.get_scripts(**params)
        return data


class ScriptApi(BaseApi):

    need_params = {
        'obj_id': ('脚本ID', 'required int'),
    }

    def get(self, request, params):
        data = user_ctl.get_script(**params)
        return data


class CreateDutyApi(BaseApi):

    need_params = {
        'name': ('角色名', 'required str'),
        'task': ('任务', 'required str'),
    }
    def post(self, request, params):
        return user_ctl.create_duty(**params)


class DutyApi(BaseApi):

    need_params = {
        'task': ('任务', 'required str'),
    }
    def post(self, request, params):
        return user_ctl.get_duty(**params)